package com.han.shadow.customerapp.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.han.shadow.customerapp.R;
import com.han.shadow.customerapp.bean.Business;
import com.han.shadow.customerapp.bean.Goods;
import com.han.shadow.customerapp.bean.Order;

import java.util.List;

/**
 * Created by ACE on 2016/4/20 0020.
 */
public class MyOrdersAdapter extends BaseAdapter {

    private List<Order> orders = null;
    private List<Business> businesses = null;
    private List<Goods> goodses = null;
    private LayoutInflater inflater = null;


    //处理0，拒绝1，发货2
    //订单状态
    public MyOrdersAdapter(List<Order> orders,List<Business> businesses,List<Goods> goodses, LayoutInflater inflater){
        this.orders = orders;
        this.businesses = businesses;
        this.goodses = goodses;
        this.inflater = inflater;
    }

    @Override
    public int getCount() {
        return orders.size();
    }

    @Override
    public Object getItem(int position) {
        return orders.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
}

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = inflater.inflate(R.layout.activity_orders_style,null);
        final Order order = orders.get(position);

        TextView orderBusName = (TextView)convertView.findViewById(R.id.orderBusName);
        TextView orderGoodsName = (TextView)convertView.findViewById(R.id.orderGoodsName);
        TextView orderGoodsState = (TextView) convertView.findViewById(R.id.orderGoodsState);

        if(businesses == null || businesses.size() == 0){
            orderBusName.setText("暂无信息");
        }else{
            for(Business bus:businesses){
                if(bus.getBid().equals(order.getBid())){
                    orderBusName.setText(bus.getName());
                    break;
                }
            }
        }
        if(goodses == null || goodses.size() == 0){
            orderGoodsName.setText("暂无信息");

        }else {
            String str = goodses.get(0).getName()+"等" +goodses.size()+"件商品";
            orderGoodsName.setText(str);
        }
        switch (order.getStatus()){
            case 0: orderGoodsState.setText("已接单。");
                break;
            case 1:  orderGoodsState.setText("被拒绝~");
                break;
            case 2: orderGoodsState.setText("发货啦!");
                break;
        }
        return convertView;
    }
}
